package com.lz.football.module.guide.setting.view
{
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import lz.controls.LButton;

	/**
	 *国家选择 
	 * @author lake
	 * 
	 */	
	public class CountrySettingPanel extends GuideBaseSelectPanel
	{
		/**
		 *国家按钮组 
		 */		
		private var countryBtns 	:Array = [];
		/**
		 *已选择的按钮 
		 */		
		private var selectBtn 		:LButton;
		/**
		 *选择国家数组索引 
		 */		
		private var selectIndex	:int;
		/**
		 *动画 
		 */		
		public var actionMC 		:MovieClip;
		
		public function CountrySettingPanel()
		{
			super();
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		override public function initUI(view:Object=null):void
		{
			_symbolSkin = view as MovieClip;
			nextBtn = _symbolSkin.nextBtn;
			descMc = _symbolSkin.descMc;
			actionMC = _symbolSkin.actionMC;
			var i :int = 1;
			var lBtn :LButton;
			for(;i<=6;i++)
			{
				lBtn = new LButton(_symbolSkin["country_"+i]);
				lBtn.enable = true;
				lBtn.buttonMode = true;
				countryBtns.push(lBtn);
				lBtn.addEventListener(MouseEvent.CLICK,countryClickHandler);
			}
			//随机一个国家
			selectIndex = Math.random() * 6;
			selectBtn = countryBtns[selectIndex];
			selectBtn.enable = false;
			selectBtn.buttonMode = false;
			selectBtn.setStatus(LButton.SELECT);
			descMc.gotoAndStop((selectIndex + 1));
			//actionMC.gotoAndStop(1);
			//actionMC.mc.gotoAndStop(1);
			//actionMC.mc.mc1.gotoAndStop(1);
			actionMC.gotoAndPlay(1);
			actionMC.mc.gotoAndPlay(1);
			actionMC.mc.mc1.gotoAndPlay(1);
			actionMC.mc.mc.mc.gotoAndStop((selectIndex + 1));
			actionMC.mc.descMc.gotoAndStop((selectIndex + 1));
			addEvtListener();
		}
		/**
		 *国家选择 
		 * @param e
		 * 
		 */		
		private function countryClickHandler(e :MouseEvent):void
		{
			var lBtn :LButton = e.currentTarget as LButton;
			if(lBtn == null)
			{
				return;
			}
			if(selectBtn)
			{
				selectBtn.enable = true;
				selectBtn.buttonMode = true;
				selectBtn.setStatus(LButton.UP);
			}
			selectBtn = lBtn;
			selectBtn.enable = false;
			selectBtn.buttonMode = false;
			selectBtn.setStatus(LButton.SELECT);
			selectIndex = countryBtns.indexOf(selectBtn);
			descMc.gotoAndStop((selectIndex + 1));
			actionMC.gotoAndPlay(1);
			actionMC.mc.gotoAndPlay(1);
			actionMC.mc.mc1.gotoAndPlay(1);
			actionMC.mc.mc.mc.gotoAndStop((selectIndex + 1));
			actionMC.mc.descMc.gotoAndStop((selectIndex + 1));
		}
		/**
		 *下一步 
		 * @param e
		 * 
		 */		
		override protected function nextHandler(e :MouseEvent):void
		{
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.COUNTRY_SELECT,(selectIndex + 1)));
		}
		/**
		 *删除事件 
		 * 
		 */		
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			for each(var lBtn :LButton in countryBtns)
			{
				lBtn.removeEventListener(MouseEvent.CLICK,countryClickHandler);
			}
		}
	}
}